/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JServingsEditorDialog.java
 *
 * Created on 2009-9-15, 11:21:57
 */
package cn.ekuma.epos.servings;

import cn.ekuma.epos.bean.util.SerivceHelper;
import cn.ekuma.epos.businesslogic.SerivceUtil;
import cn.ekuma.epos.datalogic.I_DataLogicSales;
import com.openbravo.data.basic.BasicException;
import com.openbravo.beans.JCalendarDialog;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.format.Formats;
import com.openbravo.pos.base.AppLocal;
import com.openbravo.bean.Service;
import com.openbravo.bean.Serving;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Window;
import java.util.Date;
import java.util.UUID;
import javax.swing.JFrame;

/**
 *
 * @author Administrator
 */
public class JServingsEditorDialog extends javax.swing.JDialog {

    private boolean isOK;
    private Serving servings;
    I_DataLogicSales m_dlSales;
    DirtyManager m_dirty;
    private boolean insertModel;
    JServiceEditor jServiceEditor1;
    private boolean checkState;

    /** Creates new form JServingsEditorDialog */
    public JServingsEditorDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
    }

    /** Creates new form JTicketsBagSharedList */
    private JServingsEditorDialog(java.awt.Dialog parent, boolean modal) {
        super(parent, modal);
    }

    public static JServingsEditorDialog getDialog(Component parent) {

        Window window = getWindow(parent);

        JServingsEditorDialog myreceiptsplit;

        if (window instanceof Frame) {
            myreceiptsplit = new JServingsEditorDialog((Frame) window, true);
        } else {
            myreceiptsplit = new JServingsEditorDialog((Dialog) window, true);
        }
        return myreceiptsplit;
    }

    protected static Window getWindow(Component parent) {
        if (parent == null) {
            return new JFrame();
        } else if (parent instanceof Frame || parent instanceof Dialog) {
            return (Window) parent;
        } else {
            return getWindow(parent.getParent());
        }
    }

    public void init(I_DataLogicSales dlSales, Serving inServings, boolean checkState) throws BasicException {
        initComponents();
        isOK = false;
        m_dlSales = dlSales;
        servings = inServings;
        m_dirty = new DirtyManager();
        jServiceEditor1 = new JServiceEditor(dlSales, m_dirty);
        jPanel4.add(jServiceEditor1, java.awt.BorderLayout.CENTER);
        if (inServings != null) {
            insertModel = false;
            Service theService = m_dlSales.findServiceById(inServings.getM_sServiceId());
            jServiceEditor1.writeValueDelete(theService);
            if (servings.isClosed()) {
                dialyOnly();
            }
        } else {
            insertModel = true;
            jServiceEditor1.writeValueEOF();
        }
        jRantPirce.getDocument().addDocumentListener(m_dirty);
        jrantData.getDocument().addDocumentListener(m_dirty);
        jreturnData.getDocument().addDocumentListener(m_dirty);
        m_jPrice.addActionListener(m_dirty);
        jPriceRant.addActionListener(m_dirty);
        printState();
    }

    public boolean isOK() {
        return isOK;
    }

    public Serving getServings() {
        return servings;
    }

    public boolean isInsertModel() {
        return insertModel;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jServiceId = new javax.swing.JTextField();
        m_jEnter1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jRantPirce = new javax.swing.JTextField();
        jEditService = new javax.swing.JButton();
        jm_dStartDateLabel = new javax.swing.JLabel();
        jrantData = new javax.swing.JTextField();
        m_jbtndate = new javax.swing.JButton();
        jm_dStopDateLabel = new javax.swing.JLabel();
        jreturnData = new javax.swing.JTextField();
        m_jbtndate1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jdateCount = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jcountPrice = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        m_jPrice = new javax.swing.JTextField();
        jPriceRant = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        m_jButtonOK = new javax.swing.JButton();
        m_jButtonCancel = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.PAGE_AXIS));

        jPanel1.setPreferredSize(new java.awt.Dimension(600, 250));

        jLabel1.setText(AppLocal.getIntString("label.sevice_ID")); // NOI18N

        jServiceId.setMaximumSize(new java.awt.Dimension(6, 21));

        m_jEnter1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/apply.png"))); // NOI18N
        m_jEnter1.setFocusPainted(false);
        m_jEnter1.setFocusable(false);
        m_jEnter1.setRequestFocusEnabled(false);
        m_jEnter1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jEnter1ActionPerformed(evt);
            }
        });

        jLabel2.setText(AppLocal.getIntString("label.rantPrice")); // NOI18N

        jEditService.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/search.png"))); // NOI18N
        jEditService.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jEditServiceActionPerformed(evt);
            }
        });

        jm_dStartDateLabel.setText(AppLocal.getIntString("label.rantData")); // NOI18N

        m_jbtndate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/date.png"))); // NOI18N
        m_jbtndate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jbtndateActionPerformed(evt);
            }
        });

        jm_dStopDateLabel.setText(AppLocal.getIntString("label.returnData")); // NOI18N

        jreturnData.setEditable(false);

        m_jbtndate1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/date.png"))); // NOI18N
        m_jbtndate1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jbtndate1ActionPerformed(evt);
            }
        });

        jLabel4.setText(AppLocal.getIntString("label.dateCount")); // NOI18N

        jdateCount.setEditable(false);
        jdateCount.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jLabel9.setFont(new java.awt.Font("宋体", 1, 24)); // NOI18N
        jLabel9.setText(AppLocal.getIntString("label.subtotalcash")); // NOI18N

        jcountPrice.setEditable(false);
        jcountPrice.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jcountPrice.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jLabel3.setText(AppLocal.getIntString("label.price")); // NOI18N

        jLabel8.setText(AppLocal.getIntString("label.priceRate")); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jm_dStartDateLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
                    .addComponent(jm_dStopDateLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jServiceId, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                    .addComponent(jrantData, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                    .addComponent(jreturnData, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                    .addComponent(jRantPirce, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                    .addComponent(m_jPrice, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                    .addComponent(jdateCount, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                    .addComponent(jcountPrice, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                    .addComponent(jPriceRant, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(m_jEnter1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jEditService, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(m_jbtndate, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(m_jbtndate1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel3, jLabel4, jLabel8, jm_dStartDateLabel, jm_dStopDateLabel});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jServiceId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(m_jEnter1)
                    .addComponent(jEditService))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jrantData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(jreturnData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jm_dStartDateLabel)
                                .addGap(13, 13, 13)
                                .addComponent(jm_dStopDateLabel)))
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jRantPirce, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(m_jbtndate)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(m_jbtndate1)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel8))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(m_jPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPriceRant, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jdateCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jcountPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1);

        jPanel6.setLayout(new javax.swing.BoxLayout(jPanel6, javax.swing.BoxLayout.PAGE_AXIS));

        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        m_jButtonOK.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_ok.png"))); // NOI18N
        m_jButtonOK.setText(AppLocal.getIntString("Button.OK")); // NOI18N
        m_jButtonOK.setFocusPainted(false);
        m_jButtonOK.setFocusable(false);
        m_jButtonOK.setMargin(new java.awt.Insets(8, 16, 8, 16));
        m_jButtonOK.setRequestFocusEnabled(false);
        m_jButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jButtonOKActionPerformed(evt);
            }
        });
        jPanel2.add(m_jButtonOK);

        m_jButtonCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_cancel.png"))); // NOI18N
        m_jButtonCancel.setText(AppLocal.getIntString("Button.Cancel")); // NOI18N
        m_jButtonCancel.setFocusPainted(false);
        m_jButtonCancel.setFocusable(false);
        m_jButtonCancel.setMargin(new java.awt.Insets(8, 16, 8, 16));
        m_jButtonCancel.setRequestFocusEnabled(false);
        m_jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jButtonCancelActionPerformed(evt);
            }
        });
        jPanel2.add(m_jButtonCancel);

        jPanel6.add(jPanel2);

        getContentPane().add(jPanel6);

        jPanel4.setLayout(new java.awt.BorderLayout());
        getContentPane().add(jPanel4);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-497)/2, (screenSize.height-577)/2, 497, 577);
    }// </editor-fold>//GEN-END:initComponents

    private void m_jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jButtonOKActionPerformed
        if (m_dirty.isDirty()) {
            double rantPrice;
            try {
                rantPrice = (Double) Formats.CURRENCY.parseValue(jRantPirce.getText(), 0);
            } catch (BasicException ex) {
                rantPrice = 0;
            }
            if (servings != null) {
                try {
                    if (checkState && !SerivceUtil.isServiceAble(m_dlSales, servings.getM_sServiceId(), servings.getRantData(), servings.getReturnData())) {
                        new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.serviceNoAbleInThisTime")).show(this);
                        return;
                    }
                } catch (BasicException ex) {
                    new MessageInf(MessageInf.SGN_WARNING, ex.getMessage()).show(this);
                    return;
                }
                servings.setRantPrice(rantPrice);
                isOK = true;
            }
        }
        dispose();
}//GEN-LAST:event_m_jButtonOKActionPerformed

    private void m_jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jButtonCancelActionPerformed

        dispose();
}//GEN-LAST:event_m_jButtonCancelActionPerformed

    private void m_jbtndateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jbtndateActionPerformed

        Date date;
        try {
            date = (Date) Formats.TIMESTAMP.parseValue(jrantData.getText());
        } catch (BasicException e) {
            date = null;
        }
        date = JCalendarDialog.showCalendarTime(this, date);
        if (date != null) {
            if (date.after(new Date())) {
                MessageInf msg = new MessageInf(MessageInf.SGN_NOTICE, AppLocal.getIntString("mess.rant.mustbefore"));
                msg.show(this);
            } else {
                jrantData.setText(Formats.TIMESTAMP.formatValue(date));
                servings.setRantData(date);
                printState();
            }
        }
}//GEN-LAST:event_m_jbtndateActionPerformed

    private void m_jEnter1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jEnter1ActionPerformed
        try {
            Service retService = m_dlSales.findServiceById(jServiceId.getText());
            if (retService != null) {
                assignService(retService);
            }
        } catch (BasicException ex) {
            jServiceId.setText(null);
        }
}//GEN-LAST:event_m_jEnter1ActionPerformed

    private void m_jbtndate1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jbtndate1ActionPerformed
        Date date;
        try {
            date = (Date) Formats.TIMESTAMP.parseValue(jreturnData.getText());
        } catch (BasicException e) {
            date = null;
        }
        date = JCalendarDialog.showCalendarTime(this, date);
        if (date != null) {
            if (date.after(new Date())) {
                MessageInf msg = new MessageInf(MessageInf.SGN_NOTICE, AppLocal.getIntString("mess.rant.mustbefore"));
                msg.show(this);
            } else if (date.before(servings.getRantData())) {
                MessageInf msg = new MessageInf(MessageInf.SGN_NOTICE, AppLocal.getIntString("mess.rant.mustafterRantDate"));
                msg.show(this);
            } else {
                jreturnData.setText(Formats.TIMESTAMP.formatValue(date));
                servings.setReturnData(date);
                printState();
            }
        }
    }//GEN-LAST:event_m_jbtndate1ActionPerformed

    private void jEditServiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jEditServiceActionPerformed
        Service retService = JServiceFinder.showMessage(this, m_dlSales);
        if (retService != null) {
            assignService(retService);
        }
}//GEN-LAST:event_jEditServiceActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jEditService;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JTextField jPriceRant;
    private javax.swing.JTextField jRantPirce;
    private javax.swing.JTextField jServiceId;
    private javax.swing.JTextField jcountPrice;
    private javax.swing.JTextField jdateCount;
    private javax.swing.JLabel jm_dStartDateLabel;
    private javax.swing.JLabel jm_dStopDateLabel;
    private javax.swing.JTextField jrantData;
    private javax.swing.JTextField jreturnData;
    private javax.swing.JButton m_jButtonCancel;
    private javax.swing.JButton m_jButtonOK;
    private javax.swing.JButton m_jEnter1;
    private javax.swing.JTextField m_jPrice;
    private javax.swing.JButton m_jbtndate;
    private javax.swing.JButton m_jbtndate1;
    // End of variables declaration//GEN-END:variables

    private void dialyOnly() {
        jServiceId.setEditable(false);
        jEditService.setEnabled(false);

        m_jEnter1.setEnabled(false);

        jRantPirce.setEnabled(false);

        jrantData.setEnabled(false);
        m_jbtndate.setEnabled(false);

        jreturnData.setEnabled(false);
        m_jbtndate1.setEnabled(false);
    }

    private void printState() {
        if (insertModel) {
            jServiceId.setEditable(true);
            jEditService.setEnabled(true);
            m_jEnter1.setEnabled(true);
        } else {
            jServiceId.setEditable(false);
            jEditService.setEnabled(false);
            m_jEnter1.setEnabled(false);
        }
        jRantPirce.setEnabled(true);
        jrantData.setEnabled(false);
        m_jbtndate.setEnabled(false);
        jreturnData.setEnabled(false);
        m_jbtndate1.setEnabled(false);
        jPriceRant.setEditable(false);
        m_jPrice.setEditable(false);
        if (servings != null) {
            jServiceId.setText(servings.getM_sId());
            jRantPirce.setText(Formats.CURRENCY.formatValue(servings.getRantPrice()));
            jrantData.setText(Formats.TIMESTAMP.formatValue(servings.getRantData()));
            jreturnData.setText(Formats.TIMESTAMP.formatValue(servings.getReturnData()));
            m_jPrice.setText(Formats.CURRENCY.formatValue(servings.getCyclePrice()));
            jPriceRant.setText(Formats.PERCENT.formatValue(servings.getPriceRate()));

            jdateCount.setText(String.valueOf(SerivceUtil.calcSubDays(servings)));
            jcountPrice.setText(Formats.CURRENCY.formatValue(SerivceUtil.calcSubDays(servings)));

            if (insertModel) {
                jrantData.setEnabled(true);
                m_jbtndate.setEnabled(true);
            } else {
                jreturnData.setEnabled(true);
                m_jbtndate1.setEnabled(true);
            }
            jPriceRant.setEditable(true);
            m_jPrice.setEditable(true);
        }

    }

    private void assignService(Service selectedService) {
        if (servings == null) {
            servings = new Serving(selectedService, 0);
            servings.setM_sId(UUID.randomUUID().toString());
            servings.setM_sName(SerivceHelper.printServiceName(selectedService));
        } else {
            servings.setM_sServiceId(selectedService.getId());
        }
        servings.setCyclePrice(selectedService.getCyclePrice());
        m_dirty.setDirty(true);
        jServiceEditor1.writeValueDelete(selectedService);
        printState();
    }
}
